package com.ztjy.statis.controller;

import com.github.pagehelper.PageInfo;
import com.ztjy.bean.City;
import com.ztjy.bean.CkStatis;
import com.ztjy.bean.Users;
import com.ztjy.bean.Warehouse;
import com.ztjy.repository.biz.WarehouseBiz;
import com.ztjy.statis.biz.CkStatisBiz;
import com.ztjy.sys.biz.AreaBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/statis/ck")
public class CkStatisController {
    @Autowired
    private CkStatisBiz ckbiz;
    @Autowired
    private AreaBiz abiz;
    @Autowired
    private WarehouseBiz wbiz;

    @RequestMapping("/allckstatis")
    public String findAllCkStatis(Model model, CkStatis ckStatis, @RequestParam(defaultValue = "1",value = "pageno")Integer pageNo, HttpSession session){
        Integer pageSize=6;
        Users user=(Users) session.getAttribute("currUser");
        Integer jobId = user.getJobId();
        if (jobId==6||jobId==1){
            PageInfo<CkStatis> allCkStatis = ckbiz.findAllCkStatis(ckStatis, pageNo, pageSize);
            model.addAttribute("ckstatisinfo",allCkStatis);
            if(ckStatis!=null){
                Integer cityId = ckStatis.getCityId();
                City city = abiz.findCityById(cityId);
                ckStatis.setCity(city);
            }
            model.addAttribute("ckStatis",ckStatis);
            return "forward:/statis/delivery/deliveryStatis.html";
        }else{
            return "";
        }
    }

    @RequestMapping("/ckview")
    public String findCkView(Model model,Integer id,@RequestParam(defaultValue = "1",value = "pageno")Integer pageNo){
        Integer pageSize=6;
        PageInfo<CkStatis> ckstatisById = ckbiz.findCkstatisById(id, pageNo, pageSize);
        model.addAttribute("allckbywid",ckstatisById);
        model.addAttribute("id",id);
        return "forward:/statis/delivery/deliveryView.html";
    }

    @RequestMapping("/tiaozhuang")
    @ResponseBody
    public List<CkStatis> findtiaozhuangtu(){
        List<CkStatis> findtiaozhuang = ckbiz.findtiaozhuang();
        return findtiaozhuang;
    }
}
